package org.dromara.mall.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseService;
import org.dromara.mall.domain.MallMenu;
import org.dromara.mall.service.MallMenuService;
import org.dromara.wms.domain.WmsProduct;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 菜单管理
 * @author wenrui Su
 * @date 2024-03-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/menu")
public class MallMenuController extends BaseService {

  private final MallMenuService mallMenuService;

  /**
   * 查询菜单列表
   */
  @SaCheckPermission("wms:mall:list")
  @GetMapping("/list")
  public TableDataInfo<MallMenu> menuList(MallMenu bo) {
    return TableDataInfo.build(mallMenuService.queryListUrl(bo));
  }

  /**
   * 获取菜单详细信息
   * @param id 主键
   */
  @SaCheckPermission("wms:mall:query")
  @GetMapping("/{id}")
  public R<MallMenu> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
    return R.ok(mallMenuService.queryById(id));
  }

  /**
   * 新增菜单
   */
  @SaCheckPermission("wms:mall:add")
  @Log(title = "菜单", businessType = BusinessType.INSERT)
  @RepeatSubmit()
  @PostMapping()
  public R<Void> add(@Validated(AddGroup.class) @RequestBody MallMenu bo) {
    return mallMenuService.insertByBo(bo);
  }

  /**
   * 修改菜单
   */
  @SaCheckPermission("wms:mall:edit")
  @Log(title = "菜单更新", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping()
  public R<Void> edit(@Validated(EditGroup.class) @RequestBody MallMenu bo) {
    return toAjax(mallMenuService.updateByBo(bo));
  }

  /**
   * 删除菜单
   */
  @SaCheckPermission("wms:mall:remove")
  @Log(title = "删除菜单", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
    return toAjax(mallMenuService.deleteWithValidByIds(ids));
  }

  /* PC端商城 */

  /**
   * 查询订单管理列表
   */
  @SaCheckPermission("wms:mall:navList")
  @GetMapping("/navList")
  public R<MallMenu> navList(MallMenu bo) {
    return R.ok(mallMenuService.navList(bo));
  }

  /**
   * 首页菜单栏查询
   */
  @SaCheckPermission("wms:mall:menuList")
  @GetMapping("/menuList")
  public  TableDataInfo<MallMenu> homeList() {
    return TableDataInfo.build(mallMenuService.menuList());
  }

  /**
   * 首页菜单栏查询
   */
  @SaCheckPermission("wms:mall:goodList")
  @GetMapping("/goodList")
  public  TableDataInfo<WmsProduct> goodList() {
    return TableDataInfo.build(mallMenuService.newGoodList());
  }

}
